// __PUBLIC__/js/page/admin/global/nav
require(['../../common'], function() {
  require(['global.nav'])
})

define('global.nav', [
  'jquery',
  'page/grid'
], function($, Grid) {
  'use strict';

  var $table = $('.table')
  var mygrid = new Grid($table)
  mygrid.init();

  function del(selected) {
    // sql where in
    $.post(APP + '?app=admin&m=Global&a=deleteNav', {
      ids: selected.id.join()
    })
      .done(function(data) {
        if (data == 1) {
          mygrid.del(selected.index)
        } else {
          alert(lang.delFails)
        }
      })
  }

  // 删除当前行
  $table.on('click', '.A_del', function(e) {
    e.preventDefault()
    var current = mygrid.getCurrent(this)
    var selected = {
      id: [current.id],
      index: [current.index]
    }
    del(selected)
  })

  // 删除选中行
  $(document).on('click', '#J_del', function(e) {
    e.preventDefault()
    var selected = mygrid.getSelected()
    if (!selected.count) {
      alert(lang.pleaseSelectAData)
      return
    }
    del(selected)
  })

})
